//
//  CollectionCell.swift
//  CompareBuying
//
//  Created by 唐先才 on 16/1/29.
//  Copyright © 2016年 唐先才. All rights reserved.
//

import UIKit

class CollectionCell: UICollectionViewCell {

    @IBOutlet weak var tagView: UIImageView!
    @IBOutlet weak var iconView: UIImageView!
    @IBOutlet weak var titleLab: UILabel!
    @IBOutlet weak var priceLab: UILabel!
    @IBOutlet weak var mallLab: UILabel!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
    }
   
    func configCellWithModel(model: TxcModel) {
        if (model.InfoNation) == 2 {
            iconView.image = UIImage(named: "tag_nation")
        }
        guard let img = model.MainImage, title = model.InfoTitle, price = model.CommodityPrice, name = model.MallName else {
            print("collectionCell赋值失败")
            return
        }
        tagView.sd_setImageWithURL(NSURL(string: img))
        titleLab.text = title
        priceLab.text = price
        mallLab.text = name + "供货"
    }
    
    static func collectionCellWith(collectionView: UICollectionView, dataArray: NSMutableArray, indexPath: NSIndexPath) -> UICollectionViewCell {
        if let collectionCell = collectionView.dequeueReusableCellWithReuseIdentifier("collectionCell", forIndexPath: indexPath) as? CollectionCell {
            if dataArray.count > 0 {
                if let model = dataArray[indexPath.row] as? TxcModel {
                    collectionCell.configCellWithModel(model)
                }
            }
            collectionCell.backgroundColor = UIColor.whiteColor()
            return collectionCell
        }
        return UICollectionViewCell()
    }

}





